package P003_3Operator;

import org.junit.Test;

/**
 * 三元操作符类型必须一致
 * @author xufy1
 */
public class ThirdOperator {

    @Test
    public  void test1() {
        int i = 80;

        String s = String.valueOf(i < 100 ? 90 : 100);
        //2.  3.  整型 转 浮点
        String s1 = String.valueOf(i < 100 ? 90 : 100.0);
        System.out.println("s1类型：" + getType(s1));
        System.out.println("s值：" + s + "   ，s1值：" + s1);
        System.out.println("两者是否相等：" + s.equals(s1));

        double aa=123.12;
        int bb= (int) aa;
        //4.
        ThirdOperator demo3 = new ThirdOperator();
        System.out.println("4.类型,Object ：" + getType(aa < 100 ? 90 :demo3));
        System.out.println("4.类型,Long ：" + getType(aa <100 ? 90 : 100L));
        System.out.println("4.类型,boolean/float：" + getType(aa < 333.2 ? true : 2.12f));

        //1.
        System.out.println("1. s1类型：" + getType(i > 100 ? 90 : "你好!!!"));
        int a = i < 100 ? 90 : Integer.parseInt("aaaa");
        System.out.println("1. a的值： " + a);

        //浮点默认类型
        System.out.println("类型：" + getType(123.4567890));

        //下转型，丢精度
        int ii = i > 100 ? 90 : (int) 100.12;
        System.out.println("ii的值: " + ii);


    }
    private static String getType(Object a) {
        return a.getClass().toString();
    }
}
